package view;

import java.awt.*;
import java.util.List;
import javax.swing.JComponent;
import model.GpsCoordinate;
import model.Map;
import model.Route;

public class RouteViewDecorator extends ViewDecorator {

    private Map map;
    private Route route;
    
    public RouteViewDecorator(JComponent component, Map map, Route route) {
        super(component);
        this.map = map;
        this.route = route;
    }
    
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2d = (Graphics2D)g;
        
        g2d.setStroke(new BasicStroke(2));
        g2d.setColor(Color.BLUE);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        
        Point prevPoint = null;
        List<GpsCoordinate> coords = route.getCoords();
        
        for (GpsCoordinate coord : coords) {
            
            Point coordPoint = new Point(MapViewUtil.calculateXpixels(map, coord),
                                        MapViewUtil.calculateYpixels(map, coord));
            
            if (prevPoint != null) {
                g2d.drawLine(prevPoint.x,
                            prevPoint.y,
                            coordPoint.x,
                            coordPoint.y);
            }
            
            prevPoint = coordPoint;
        }
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
}